home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earcd / phase5 / lha-ppc / src / patmatch.c < prev    next >
C/C++ Source or Header  |  1997-12-04  |  827b  |  43 lines

  1. /*
  2.  *      Returns true if string s matches pattern p.
  3.  */
  4.  
  5. #include <ctype.h>
  6.  
  7. /* p == pattern             */
  8. /* s == string to match     */
  9. /* f == flag for case force */
  10.  
  11. int patmatch(char *p, char *s, int f)
  12. {
  13.     char pc;            /* a single character from pattern */
  14.     char c;
  15.  
  16.     c = *p++;
  17.     while (pc = ((f && islower(c)) ? toupper(c) : c))
  18.     {
  19.     if (pc == '*')
  20.     {
  21.         do {            /* look for match till s exhausted */
  22.         if (patmatch (p, s, f))
  23.             return (1);
  24.         } while (*s++);
  25.         return (0);
  26.     }
  27.     else
  28.     {
  29.         if (*s == 0)
  30.         return (0);        /* s exhausted, p not */
  31.         else if (pc == '?')
  32.             s++;            /* matches all, just bump */
  33.             else
  34.         {
  35.         c = *s++;
  36.         if (pc != ((f && islower(c)) ? toupper(c) : c))
  37.             return (0);
  38.         }
  39.     }
  40.     }
  41.     return (!*s);            /* p exhausted, ret true if s exhausted */
  42. }
  43.